package com.twu.excercise;

import java.util.Scanner;

import static com.twu.excercise.Triangle.readNumber;

public class Diamond {
    public static void main(String[] args) {
        int n;

        n=readNumber();
        printIsoscelesTriangle(n);

        n=readNumber();
        printDiamond(n);

        n=readNumber();
        String name=readName();
        printDiamondWithName(n,name);
    }

    private static void printDiamondWithName(int n, String name) {
        printIsoscelesTriangle(n);
        System.out.println(name);
        printReverseIsoscelesTriangle(n,false);
    }

    private static void printDiamond(int n) {
        printIsoscelesTriangle(n);
        printReverseIsoscelesTriangle(n-1,true);
    }

    private static void printReverseIsoscelesTriangle(int n, boolean extraSpaceNeeded) {
        int noOfAsterisks=(2*n)-1;
        for(int i=n;i>0;i--) {
            printWhiteSpace(n-i+1);
            if(extraSpaceNeeded)
                System.out.print(" ");
            printAsterisksLine(noOfAsterisks);
            noOfAsterisks -=2;
        }
    }

    private static void printIsoscelesTriangle(int n) {
        int noOfAsterisks=1;
        for(int i=0;i<n;i++) {
            printWhiteSpace(n-i);
            printAsterisksLine(noOfAsterisks);
            noOfAsterisks +=2;
        }
    }

    private static void printWhiteSpace(int n) {
        for(int i=0;i<n;i++)
            System.out.print(" ");
    }

    private static void printAsterisksLine(int n) {
        for(int i=0;i<n;i++)
            System.out.print("*");
        System.out.println("");
    }

    private static String readName() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter your name");
        return scanner.nextLine();
    }
}
